import os
import traceback

from db import *
from log import *

def doParse(db):
    Log.t("Parsing URLs finishes")


def init():
    try:
        dir = os.getcwd() + "\\orig"
        if os.path.exists(dir) == False:
            os.mkdir(dir)
    except Exception, e:
        Log.e(traceback.format_exc())
        Log.e("Error: failed to create dir of " + dir)

if __name__ == '__main__':
    Log.init()
    Log.t("Starting Alchemy...")

    Log.t("Starting database...")
    init()
    dbRoot = os.getcwd() + "\\db"
    db = MyDB()
    db.connect(dbRoot)

    Log.t("Parsing URLs...")
    doParse(db)

    db.close()

    Log.t("Done")
    Log.close()